package com.erju.controller;

import com.erju.pojo.EquipApplication;
import com.erju.pojo.EquipRepair;
import com.erju.pojo.VO.PageAll;
import com.erju.service.EquipmentService;
import com.erju.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author sunyuan
 * @date 2022/4/6 18:30
 */
@RestController
@RequestMapping("/equipment")
public class EquipmentController {

    private static final Logger log = LoggerFactory.getLogger(EquipmentController.class);
    @Autowired
    EquipmentService equipmentService;

    /**
     * 查询所有器材
     *
     * @return
     */
    @RequestMapping("/selectAllEquipment")
    public Result selectAllEquipment(@RequestBody HashMap<String, String> map) {
        return equipmentService.selectAllEquipment(map);
    }

    /**
     * 我要申请
     *
     * @param equipApplication
     * @return
     */
    @RequestMapping("/applicationEquipment")
    public Result applicationEquipment(@RequestBody EquipApplication equipApplication) {
        System.out.println("equipApplication----->" + equipApplication);
        return equipmentService.applicationEquipment(equipApplication);
    }

    /**
     * 查看所有申请列表
     *
     * @return
     */
    @RequestMapping("/selectAllApplication")
    public Result selectAllApplication(@RequestBody HashMap<String, String> map) {
        System.out.println("selectAllApplication-->" + map);
        return equipmentService.selectAllApplication(map);
    }

    /**
     * 处理申请列表
     *
     * @param equipApplication
     * @return
     */
    @RequestMapping("/toHandleApplication")
    public Result toHandleApplication(@RequestBody EquipApplication equipApplication) {
        System.out.println("toHandleApplication-->" + equipApplication);
        return equipmentService.toHandleApplication(equipApplication);
    }

    /**
     * 查询我的所有预约信息
     *
     * @param pageAll
     * @return
     */
    @RequestMapping("/selectEquipApplicationInfo")
    public Result selectEquipApplicationInfo(@RequestBody PageAll pageAll) {
        log.info("selectEquipApplicationInfo方法接受的参数--->" + pageAll);
        return equipmentService.selectEquipApplicationInfo(pageAll);
    }


    /**
     * 查询我的实验器材(预约成功的)
     *
     * @param pageAll
     * @return
     */
    @RequestMapping("/selectAgreeEquipApplicationInfo")
    public Result selectAgreeEquipApplicationInfo(@RequestBody PageAll pageAll) {
        log.info("selectAgreeEquipApplicationInfo方法接受的参数--->" + pageAll);
        return equipmentService.selectAgreeEquipApplicationInfo(pageAll);
    }

    /**
     * 查询所有报修情况
     *
     * @param pageAll
     * @return
     */
    @RequestMapping("/selectAllRepairs")
    public Result selectAllRepairs(@RequestBody PageAll pageAll) {
        log.info("selectAllRepairs的参数-->" + pageAll);
        return equipmentService.selectAllRepairs(pageAll);
    }

    /**
     * 报修
     *
     * @param equipRepair
     * @return
     */
    @RequestMapping("/reportRepairs")
    public Result reportRepairs(@RequestBody EquipRepair equipRepair) {
        log.info("reportRepairs的参数--->" + equipRepair);
        return equipmentService.reportRepairs(equipRepair);
    }


    /**
     * 学生 / 老师提出归还请求
     * 参数 (id,application_name)
     *
     * @param equipApplication
     * @return
     */
    @RequestMapping("/toReturnBack")
    public Result toReturnBack(@RequestBody EquipApplication equipApplication) {
        log.info("toReturnBack接受的参数--->" + equipApplication);
        return equipmentService.toReturnBack(equipApplication);
    }


    /**
     * 管理员处理报修
     * 参数 ( id,repair_name,repair_phone,repair_time)
     *
     * @param equipRepair
     * @return
     */
    @RequestMapping("/handleRepairs")
    public Result handleRepairs(@RequestBody EquipRepair equipRepair) {
        log.info("handleRepairs接受的参数--->" + equipRepair);
        System.out.println(equipRepair);
        return equipmentService.handleRepairs(equipRepair);
    }

}
